<template>
  <div class="visitor-alreadyVisited">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">项目企业名称:</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.projectCompanyName" placeholder="请填写项目企业名称" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">选择类型:</div>
        <div class="input-item">
          <a-select ref="select" v-model="queryParam.projectCompanyType" placeholder="请选择">
            <a-select-option v-for="(item, index) in project_company_type" :key="index" :value="item.value">
              {{ item.text }}
            </a-select-option>
          </a-select>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">服务时间:</div>
        <div class="time-item">
          <start-end-time
            :times="times"
            :showTime="{ format: 'HH:mm:ss' }"
            format="YYYY-MM-DD HH:mm:ss"
            @timeChange="timeChange"
            :resetTime="resetTime"
          ></start-end-time>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">服务警员:</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.joinPoliceUserName" placeholder="请填写" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">上传人员:</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.uploadPoliceUserName" placeholder="请填写" />
        </div>
      </div>

      <div class="btn-wrap">
        <a-button class="searchBtn" @click="searchQuery(queryParam.startTime, queryParam.endTime)" type="primary">
          搜索
        </a-button>
        <a-button class="resetBtn" @click="searchReset()" type="primary"> 重置 </a-button>
      </div>
    </div>

    <div>
      <a-table
        rowKey="id"
        class="tableList"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        @change="handleTableChange"
      >
        <template #time="record">
          <a-tooltip placement="topLeft">
            <template slot="title">
              <span>{{ record.startTime.split(' ')[0] }} - {{ record.endTime.split(' ')[0] }}</span>
            </template>
            <span>{{ record.startTime.split(' ')[0] }} - {{ record.endTime.split(' ')[0] }}</span>
          </a-tooltip>
        </template>
        <template #projectCompanyType="record">
          <span>{{ get_dict_type(project_company_type, record.projectCompanyType) }}</span>
        </template>
        <template v-slot:action="records">
          <span class="operation deatil-color" @click="detailHandle(records)">详情 </span>
        </template>
      </a-table>
    </div>

    <detailModal ref="detailModal" />
  </div>
</template>
<script>
import startEndTime from '@/components/startEndTime'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mapState } from 'vuex'
import { ajaxGetDictItems } from '@/api/api'
import detailModal from './modules/serviceDetail'
export default {
  name: 'visitor-alreadyVisited',
  components: { startEndTime, detailModal },
  mixins: [JeecgListMixin],
  computed: {
    ...mapState({
      isPoliceAgencyId: (state) => state.user.isPoliceAgencyId,
    }),
  },
  watch: {
    isPoliceAgencyId: {
      handler(v) {
        this.queryParam.policeAgencyId = v.id ? v.id : ''
        this.searchQuery()
      },
    },
  },
  data() {
    return {
      url: {
        list: '/common/project_company_serve_record/page',
        tree: true,
      },
      project_company_type: [], // 线索类型
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '项目企业名称',
          dataIndex: 'projectCompanyId_dictText',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '类型',
          scopedSlots: { customRender: 'projectCompanyType' },
          ellipsis: true,
          align: 'center',
        },
        {
          title: '服务内容',
          dataIndex: 'serveContent',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '服务警员',
          dataIndex: 'policeUserNames',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '服务时段',
          align: 'center',
          width: 260,
          scopedSlots: { customRender: 'time' },
          ellipsis: true,
        },
        {
          title: '上传人员',
          dataIndex: 'userName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '上传时间',
          dataIndex: 'createTime',
          width: 180,
          ellipsis: true,
          align: 'center',
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          align: 'center',
        },
      ],
      disableMixinCreated: true,
    }
  },
  mounted() {
    this.getDist()
  },
  methods: {
    async getDist() {
      let { result: project_company_type } = await ajaxGetDictItems({ code: 'project_company_type' })
      this.project_company_type = project_company_type
    },
    get_dict_type(list, type) {
      let res = list.find((item) => item.value == type)
      if (res && res.title) {
        return res.title
      } else {
        return '暂无'
      }
    },
    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.startTime = this.$moment(v).valueOf()
      } else {
        this.queryParam.endTime = this.$moment(v).valueOf()
      }
      if (v == null) {
        this.queryParam.startTime = null
        this.queryParam.endTime = null
      }
    },

    detailHandle(records) {
      this.$refs.detailModal.show(records)
    },
  },
}
</script>
